package object._02getclass;

import java.lang.reflect.Constructor;

public class Demo02 {
    public static void main(String[] args) {
        Person person = new Person();
        //获取Person类的字节码文件对象
        Class cls = person.getClass();//cls = class _09object._02getclass.Person
        System.out.println("cls = " + cls);
        System.out.println("--------------------");
        //通过字节码文件对象来获取Person类中的所有信息
        //获取全类名
        String name = cls.getName();
        System.out.println("name = " + name);
        System.out.println("--------------------");
        //获取简单名
        String simpleName = cls.getSimpleName();
        System.out.println(simpleName);
        System.out.println("--------------------");

        //获取类中的所有构造方法
        Constructor[] declaredConstructors = cls.getDeclaredConstructors();
        for (Constructor declaredConstructor: declaredConstructors) {
            System.out.println(declaredConstructor);
        }
        System.out.println("--------------------");
        //获取父类
        Class superClass = cls.getSuperclass();
        System.out.println("superClass = " + superClass);
        System.out.println("--------------------");
        //获取接口信息
        for(Class anInterface:cls.getInterfaces()) {
            System.out.println("anInterface = " + anInterface);
        }

    }
}
interface IA {
    void m1();
}
class Person implements IA {
    public String name;
    int age;
    @Override
    public void m1() {
        System.out.println("Person m1");
    }

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}





